/*
 *  CSE 40166, Computer Graphics, Fall 2013
 *
 *  PORT
 *  File: drawShapes.cpp
 *
 *  Kevin Sonnen
 *
 *  Description: Contains implementations for drawing commonly used shapes in OpenGL
 *
 */
#include "drawShapes.h"

//
// void drawCircle(float radius)
//
// Draw a circle at the origin with specified radius
//
void drawCircle( const float &radius, const bool &noFill ) {
	// Specify the number of vertices for the circle
	const int numVertices = 100;
	
	// If noFill is true, fill the circle in.
	if (!noFill) {
		glBegin( GL_TRIANGLE_FAN ); {
			// Specify the center of the triangle fan/circle at the origin
			glVertex2f( 0, 0 );
			for ( int currentVertex=0; currentVertex < numVertices; ++currentVertex ) {
				float t = (currentVertex / (float)(numVertices-1)) * 2 * M_PI;
				glVertex2f( radius*cosf(t), radius*sinf(t) );
			}
			glVertex2f(radius, 0);
		} glEnd();
	} 
	
	// If orbit is true, only draw the circle outline
	else {
		glBegin( GL_LINE_STRIP ); {
			for (int currentVertex = 0; currentVertex < numVertices; ++currentVertex) {
				float t = (currentVertex / (float)(numVertices-1)) * 2 * M_PI;
				glVertex2f( radius*cosf(t), radius*sinf(t) );
			}
			glVertex2f(radius, 0);
		}; glEnd();
	}	
}

//
// void drawPolygon(const int numSides, const int radius, const bool fill)
//
// Draw a regular polygon with the specified number of sides, radius, and a boolean option to fill it or not
//
void drawPolygon(const int &numSides, const int &radius, const bool &fill) {
	if (fill) {
		glBegin( GL_POLYGON ); {
			for (int i=0; i<numSides; ++i) {
				glVertex2f((float)radius*sinf((float)i/(float)numSides*2*M_PI), (float)radius*cosf((float)i/(float)numSides*2*M_PI));
			}
		}; glEnd();
	} else {
		glBegin( GL_LINES ); {
			for (int i=0; i<=numSides; ++i) {
				glVertex2f((float)radius*sinf((float)i/(float)numSides*2*M_PI), (float)radius*cosf((float)i/(float)numSides*2*M_PI));
				glVertex2f((float)radius*sinf((float)(i+1)/(float)numSides*2*M_PI), (float)radius*cosf((float)(i+1)/(float)numSides*2*M_PI));
			}
		}; glEnd();
	}
}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//
// Functions to draw specified letters. Take location and size parameters
//
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
void drawA(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			glVertex2f( -width/2, -height/2 );
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( 0, height/2-(letterWidth*3) );
			glVertex2f( 0, height/2 );
			
			glVertex2f( width/2, -height/2 );
			glVertex2f( width/2-letterWidth, -height/2 );
			glVertex2f( 0, height/2-(letterWidth*3) );
			glVertex2f( 0, height/2 );
		}; glEnd();
	}; glPopMatrix();

	
}

void drawE(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Draw the vertical part of the E
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2+letterWidth, height/2 );
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( -width/2, -height/2 );
			
			// Draw the top horizontal portion of the E
			glVertex2f( -width/2+letterWidth, height/2 );
			glVertex2f( -width/2+letterWidth, height/2-letterWidth );
			glVertex2f( width/2, height/2-letterWidth );
			glVertex2f( width/2, height/2 );
			
			// Draw the middle horizontal portion of the E
			glVertex2f( -width/2+letterWidth, -letterWidth/2 );
			glVertex2f( -width/2+letterWidth, letterWidth/2 );
			glVertex2f( width/2, letterWidth/2 );
			glVertex2f( width/2, -letterWidth/2 );
			
			// Draw the bottom horizontal portion of the E
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( -width/2+letterWidth, -height/2+letterWidth );
			glVertex2f( width/2, -height/2+letterWidth );
			glVertex2f( width/2, -height/2 );
		}; glEnd();
	}; glPopMatrix();	
}

void drawH(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			// Draw the left vertical part of the H
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2+letterWidth, height/2 );
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( -width/2, -height/2 );
			
			// Draw the middle horizontal portion of the H
			glVertex2f( -width/2+letterWidth, -letterWidth/2 );
			glVertex2f( -width/2+letterWidth, letterWidth/2 );
			glVertex2f( width/2-letterWidth, letterWidth/2 );
			glVertex2f( width/2-letterWidth, -letterWidth/2 );
			
			// Draw the right vertical part of the H
			glVertex2f( width/2, height/2 );
			glVertex2f( width/2-letterWidth, height/2 );
			glVertex2f( width/2-letterWidth, -height/2 );
			glVertex2f( width/2, -height/2 );
		}; glEnd();
	}; glPopMatrix();	
}

void drawL(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Draw the vertical part of the L
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2+letterWidth, height/2 );
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( -width/2, -height/2 );
			
			// Draw the Horizontal part of the L
			glVertex2f( -width/2+letterWidth, -height/2 );
			glVertex2f( -width/2+letterWidth, -height/2+letterWidth );
			glVertex2f( width/2, -height/2+letterWidth );
			glVertex2f( width/2, -height/2 );
		}; glEnd();
	}; glPopMatrix();	
}

void drawP(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			// If we don't set a color here, the letter will be drawn in whatever the previous color used was
			// Therefore, When the letter is drawn after the port, it fluctuates colors
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Left vertical bar
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2, -height/2 );
			glVertex2f( -width/2 + letterWidth, -height/2 );
			glVertex2f( -width/2 + letterWidth, height/2 );
			
			glVertex2f( -width/2 + letterWidth, height/2 );
			glVertex2f( width/2 - letterWidth/2, height/2 );
			glVertex2f( width/2 - letterWidth/2, 0 );
			glVertex2f( -width/2 + letterWidth, 0 );
			
			glVertex2f( width/2 - letterWidth/2, height/2 );
			glVertex2f( width/2 - letterWidth/2, 0 );
			glVertex2f( width/2, letterWidth/2 );
			glVertex2f( width/2, height/2-letterWidth/2 );
		}; glEnd();
	}; glPopMatrix();	
}

void drawR(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Left vertical bar
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2, -height/2 );
			glVertex2f( -width/2 + letterWidth, -height/2 );
			glVertex2f( -width/2 + letterWidth, height/2 );
			
			glVertex2f( -width/2 + letterWidth, height/2 );
			glVertex2f( width/2 - letterWidth/2, height/2 );
			glVertex2f( width/2 - letterWidth/2, 0 );
			glVertex2f( -width/2 + letterWidth, 0 );
			
			glVertex2f( width/2 - letterWidth/2, height/2 );
			glVertex2f( width/2 - letterWidth/2, 0 );
			glVertex2f( width/2, letterWidth/2 );
			glVertex2f( width/2, height/2-letterWidth/2 );
			
			glVertex2f( -width/2 + letterWidth, 0 );
			glVertex2f( -width/2 + letterWidth*2, 0 );
			glVertex2f( width/2, -height/2 );
			glVertex2f( width/2 - letterWidth, -height/2 );
		}; glEnd();
	}; glPopMatrix();
}

void drawT(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Draw upper bridge of T
			glVertex2f( -width/2, height/2 );
			glVertex2f( width/2, height/2 );
			glVertex2f( width/2, height/2-letterWidth );
			glVertex2f( -width/2, height/2-letterWidth );
			
			// Draw lower vertical bar of T
			glVertex2f( -letterWidth/2, height/2-letterWidth );
			glVertex2f( letterWidth/2, height/2-letterWidth );
			glVertex2f( letterWidth/2, -height/2 );
			glVertex2f( -letterWidth/2, -height/2 );
		}; glEnd();
	}; glPopMatrix();

	
}

void drawY(const int &width, const int &height, const int &letterWidth, const int &x, const int &y) {
	glPushMatrix(); {
		glTranslatef( x, y, 0 );
		glBegin( GL_QUADS ); {
			//glColor3f( 0.0f, 0.9f, 0.0f );
			// Draw upper left branch of Y
			glVertex2f( -width/2, height/2 );
			glVertex2f( -width/2+letterWidth, height/2 );
			glVertex2f( 0, letterWidth );
			glVertex2f( -letterWidth/2, 0 );
			
			// Draw upper right branch of Y
			glVertex2f( width/2, height/2 );
			glVertex2f( width/2-letterWidth, height/2 );
			glVertex2f( 0, letterWidth );
			glVertex2f( letterWidth/2, 0 );
			
			// Draw vertical bar of Y
			glVertex2f( -letterWidth/2, letterWidth );
			glVertex2f( letterWidth/2, letterWidth );
			glVertex2f( letterWidth/2, -height/2 );
			glVertex2f( -letterWidth/2, -height/2 );
		}; glEnd();
	}; glPopMatrix();

	
}
